package sz.com.battleship.game;

import sz.com.battleship.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Client extends Activity implements OnClickListener {
   private Button connectButton;
   private EditText ipAdress;
   private EditText serverPort;
   private String serverIpAddress = "";//"192.168.0.190";
   private String port = "";

   @Override
   public void onCreate(Bundle savedInstanceState)  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.client);
      connectButton = (Button) findViewById(R.id.clientConnectButton);
      ipAdress = (EditText) findViewById(R.id.ipAdressText);
      serverPort = (EditText) findViewById(R.id.serverPort);
      serverPort.setText("6000");
      connectButton.setOnClickListener(this);

          
   }
   
   @Override
   public void onClick(View v) {
  	 
  	 if(v.getId() == R.id.clientConnectButton)
  	 {
	     serverIpAddress = ipAdress.getText().toString();
	     port = serverPort.getText().toString();
	     if (!serverIpAddress.equals("") && !port.equals("")) 
	     {
	  	   Intent socketIntent =  new Intent(getApplicationContext(),GameScreen.class );
	  	   socketIntent.putExtra("IP", serverIpAddress);
	  	   socketIntent.putExtra("PORT", Integer.parseInt(port));
	  	   startActivity(socketIntent);  
	     }  
  	 }
   }
}
